/**
 * Created by mac on 2018/9/5.
 */

import * as actionTypes from './actionTypes';
import { fromJS } from 'immutable';

//const defaultState = {
//    focused: false,
//    search_list: []
//}

const defaultState = fromJS({
    focused: false,
    search_list: [],
    moused: false,
});

export default (state = defaultState, action) => {
    //const newState = JSON.parse(JSON.stringify(state));
    //if (action.type === actionTypes.SEARCH_FOCUS) {
    //    newState.focused = true;
    //    return newState;
    //}
    //if (action.type === actionTypes.SEARCH_BLUR) {
    //    newState.focused = false;
    //    return newState;
    //}
    //
    //if (action.type === actionTypes.GET_SEARCH_CONTENT_LIST) {
    //    newState.search_list = action.data;
    //    return newState;
    //}
    //return state;

    // 使用immutable.js后的写法
    switch (action.type) {
        case actionTypes.SEARCH_FOCUS:
            return state.set('focused', true);
        case actionTypes.SEARCH_BLUR:
            return state.set('focused', false);

        case actionTypes.GET_SEARCH_CONTENT_LIST:
            return state.set('search_list', action.data);

        case actionTypes.SEARCH_CONTENTVIEW_MOUSE_ENTER:
            return state.set('moused', true);

        case actionTypes.SEARCH_CONTENTVIEW_MOUSE_LEAVE:
            return state.set('moused', false);
        default:
            return state;
    }

}